

package com.ylbh.modules.sys.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.*;
import com.ylbh.common.validator.Assert;
import com.ylbh.common.validator.ValidatorUtils;
import com.ylbh.common.validator.group.AddGroup;
import com.ylbh.common.validator.group.UpdateGroup;
import com.ylbh.modules.sys.entity.SysUserEntity;
import com.ylbh.modules.sys.form.PasswordForm;
import com.ylbh.modules.sys.service.SysUserRoleService;
import com.ylbh.modules.sys.service.SysUserService;
import org.apache.commons.lang.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 系统工具类
 */
@RestController
@RequestMapping("/sys/tools")
public class SysUtilController extends AbstractController {
	/**
	 * 按指定前缀上传图片
	 */
	@SysLog("系统工具类【上传图片】")
	@PostMapping("/uploadImg/{prefix}")
	@RequiresPermissions("sys:user:list")
	public CommonResult<String> list(@PathVariable String prefix,@RequestBody MultipartFile file){
        if(file==null){
            return Ref.error("上传图片时，图片为空");
        }
        OSSClient ossClient = new OSSClient();

        try {
            String suffix = DateHelper.getYearMonth();
            String name = ossClient.uploadImg2Oss(file,"consumer/"+prefix+"/",suffix);
            String url = "https://image.yilianbaihui.cn/consumer/"+prefix+"/"+suffix+"/"+name;
            return Ref.ok(url);
        } catch (Exception e) {
            e.printStackTrace();
            return Ref.error("上传图片失败");
        }
	}
}
